package com.example.lab2cv;

import android.app.ListFragment;
import android.net.Uri;
import android.os.Bundle;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class FragmentList extends ListFragment {
	QR qr;
	Map ma;
	Information info;
	Contact con;

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		ListAdapter adapter = new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, MainActivity.choices);
		setListAdapter(adapter);
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {

		String clickedDetail = (String) l.getItemAtPosition(position);
		FragmentTransaction fragTran = getActivity().getFragmentManager()
				.beginTransaction();

		if (clickedDetail.contentEquals("Information")) {
			if (info == null)
				info = new Information();
			fragTran.replace(R.id.phone_container, info);
			fragTran.addToBackStack(null);
			fragTran.commit();

		}
		if (clickedDetail.contentEquals("Map")) {

			if (ma == null)
				ma = new Map();
			fragTran.replace(R.id.phone_container, ma);
			fragTran.addToBackStack(null);
			fragTran.commit();

		}

		if (clickedDetail.contentEquals("QR-code")) {

			if (qr == null)
				qr = new QR();
			fragTran.replace(R.id.phone_container, qr);
			fragTran.addToBackStack(null);
			fragTran.commit();

		}

		if (clickedDetail.contentEquals("Homepage")) {
			Intent browserIntent = new Intent(Intent.ACTION_VIEW,
					Uri.parse("http://company.wizards.com/"));
			startActivity(browserIntent);
		}

		if (clickedDetail.contentEquals("Contact")) {

			if (con == null)
				con = new Contact();
			fragTran.replace(R.id.phone_container, con);
			fragTran.addToBackStack(null);
			fragTran.commit();

		}

	}

}